package cn.lingnan.service.serviceimpl;

import cn.lingnan.mapper.LoginMapper;
import cn.lingnan.pojo.dto.UserLoginDTO;
import cn.lingnan.pojo.dto.UserRegisterDTO;
import cn.lingnan.pojo.entity.Admin;
import cn.lingnan.pojo.entity.User;
import cn.lingnan.service.LoginService;
import cn.lingnan.utils.MD5;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;
    @Override
    public User userLogin(UserLoginDTO userLoginDTO) {
     String   MD5PWD=MD5.md5Encrypt(userLoginDTO.getPassword());
        userLoginDTO.setPassword(MD5PWD);
        return  loginMapper.userLogin(userLoginDTO);
    }

    @Override
    public void userRegister(UserRegisterDTO userRegisterDTO) {
        User user = new User();
        BeanUtils.copyProperties(userRegisterDTO, user);
        String MD5PWD=MD5.md5Encrypt(userRegisterDTO.getPassword());
        user.setPassword(MD5PWD);
        user.setCreateTime(LocalDateTime.now());
        user.setUpdateTime(LocalDateTime.now());
        user.setStatus(1);
        loginMapper.userRegister(user);
    }

    @Override
    public Admin AdminLogin(String account, String password) {
        String MD5PWD=MD5.md5Encrypt(password);

        return loginMapper.AdminLogin(account,MD5PWD);



    }
}
